<template>
  <div id="changedialog">
    <commonformdialog
      :isshowDialogs="isshowDialog"
      :dialogTitle="dialogTitle"
      @closetextDialog="closetextDialog"
      @confirmbtn="confirmbtn"
      :dialogWidth="'750px'"
    >
      <div class="innerLoding">
        <el-row>
          <el-form
            :model="formData"
            :rules="rules"
            ref="ruleForm"
            label-width="120px"
            size="small"
          >
            <el-row>
              <el-col :span="20">
                <el-form-item label="标题：" prop="title">
                  <el-input
                    placeholder="请输入部门名称"
                    type="text"
                    clearable
                    v-model="formData.title"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="20">
                <el-form-item label="描述：" prop="description">
                  <el-input
                    placeholder="请输入描述"
                    type="textarea"
                    clearable
                    :rows="3"
                    v-model="formData.description"
                      resize="none"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-row>
      </div>
    </commonformdialog>
  </div>
</template>

<script type="text/javascript">
//引入弹窗
import commonformdialog from "@/components/commondialog/commondialog";
import uploadimg from "@/components/uploadimg/uploadimg";

import { userRoleCreate, userRoleupdate } from "@/api/userManagement";
export default {
  data() {
    return {
      showPicker: false,
      multipleopen: true,
      imgList: [],
      formData: {
        title: "",
        description: "",
  
      },
      rules: {
        title: [
          { required: true, message: "请输入部门名称", trigger: "blur" },
        ],
      
      },
    };
  },
  props: {
    //是否显示弹窗
    isshowDialog: {
      type: Boolean,
      default: false,
      required: true,
    },
    //表单的名字
    dialogTitle: {
      type: String,
      default: "",
      required: true,
    },
    //是编辑还是新增
    formType: {
      type: Number,
      default: 0,
    },
    prepareLineOption: {
      type: Array,
    },
    dialogdata: {
      type: Object,
    },
  },
  components: {
    commonformdialog,
  },
  methods: {
   
    closetextDialog() {
      this.$emit("closedialog");
    },

    confirmbtn() {
      this.$refs["ruleForm"].validate(async (valid) => {
        if (!valid) return;
        let {title,description} = this.formData;
        let params= {title,description} 
        console.log(params)
        let data;
        if (this.formType == 0) {
          data = await userRoleCreate(params);
        } else {
          params.id=this.formData.id
          data = await userRoleupdate(params);
        }
        if (data.code == "0000") {
          this.$message({
            type: "success",
            message: data.msg,
          });
          this.$emit("confirm");
        }
      });
    },


  },
  watch: {
    isshowDialog: function (val) {
      if (!val) {
        this.$refs["ruleForm"].resetFields();
      }
    },
    dialogdata: function (val) {
      this.formData = val;
    },
  },
  created() {},
};
</script>

<style lang="scss" scoped>
::v-deep {
  #InputSearch {
    display: none !important;
  }
  .grid-emojis {
    grid-template-columns: repeat(10, 10%) !important;
  }
  .small {
    position: absolute;
    z-index: 9;
    left: -45px;
    top: 30px;
  }
}
</style>
